<%
layout("/layouts/platform.html"){
%>
<section class="content-wrap bg-white">
    <header class="header navbar bg-white shadow">
		<div class="btn-group tool-button" style="padding:8px 0">
		<form id="searchForm">
			<table>
           		<tbody>
           			<tr>
                  		<td>
                       		<input type="text" id="batch_no" name="batch_no" onclick="this.value=''" class="form-control" placeholder="批次编号" autofocus>
                        </td>
                        <td style="padding-left: 5px;">
                            <button id="searchBtn" type="button" class="btn btn-default"><i class="fa fa-search"></i>&nbsp;查询</button>
                      	</td>
                        </tr>
                    </tbody>
            </table>
             </form>
		</div>
	    <div class="pull-right offscreen-right">
	         <a class="btn btn-default navbar-btn" href="${base}/platform/physical/add" data-toggle="modal" data-target="#addModal" ><i class="fa fa-plus"></i>&nbsp;新增</a>
	         <a class="btn btn-default navbar-btn" href='javascript:;' onclick='exportData()'><i class="fa fa-download"></i>数据导出</a>
		</div>
	</header>
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border">
            <input id="unitid" type="hidden">
            <table class="table table-bordered table-striped mg-t datatable">
                <thead>
                <tr>
                    <th>批次</th>
                    <th>序号</th>
                    <th>验证码</th>
                    <th>创建日期</th>
                    <th>状态</th>
            </table>
        </div>
    </div>
</section>
	<div id="dialogExport" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	                <h4 class="modal-title">导出数据</h4>
	            </div>
	            <div class="modal-body">
	                <div class="row">
	                    <div class="col-xs-12">
	                        	确定导出吗？ <br/>
	                    </div>
	                </div>
	            </div>
	            <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
	                <button id="okExport" type="button" class="btn btn-primary" data-loading-text="正在导出...">确 定</button>
	            </div>
	        </div>
	    </div>
	</div>
<div id="dialogDetail" class="modal fade bs-modal" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

        </div>
    </div>
</div>
<script language="JavaScript">
	var datatable;
	function initDatatable() {
	    datatable = $('.datatable').DataTable({
	        "dom": '<"toolbar">frtip',
	        "searching": false,
	        "processing": false,
	        "serverSide": true,
	        "select": true,
	        "ordering": true,
	        "language": {
	            "url": "${base}/assets/plugins/datatables/cn.json"
	        },
	        "preDrawCallback": function () {
	            sublime.showLoadingbar($(".main-content"));
	        },
	        "drawCallback": function () {
	            sublime.closeLoadingbar($(".main-content"));
	        },
	        "ajax": {
	            "url": "${base}/platform/physical/data",
	            "type": "post",
	            "data": function (d) {
	            	d.batch_no=$('#batch_no').val();
	            }
	        },
	        "order": [[0, "asc"]],
	        "columns": [
	            {"data": "batch_id", "bSortable": true},
	            {"data": "sn", "bSortable": true},
	            {"data": "code", "bSortable": true},
	            {"data": "createAt", "bSortable": true},
	            {"data": "state", "bSortable": true}
	        ],
	        "columnDefs": [
				{
					"render": function (data, type, row) {
						 return  getBatchNo(data);
				     },
				     "targets": 0
				 },
					{
	                 	"render": function (data, type, row) {
	                   		if (data) {
	                      		return moment(parseInt(data*1000)).format("YYYY-MM-DD HH:mm:ss");
	                    	}
	                      	return '';
	             		 },
	                  	"targets": 3
	               	},
				 {
						"render": function (data, type, row) {
							 if(data==0){
								 return "未用";
							 }else if(data==1){
								 return "已领取";
							 }else if(data==2){
								 return "已使用";
							 }else if(data==6){
								 return "已出售";
							 }
					     },
					     "targets": 4
					 }
	        ]
	    });
	    $("#searchBtn").on('click', function () {
	        datatable.ajax.reload();
	    });
	}
	$(function () {
	    initDatatable();
	});
	//导出
	function exportData(){
		var dialog = $("#dialogExport");
        dialog.modal("show");
        dialog.find("#okExport").unbind("click");
        dialog.find("#okExport").bind("click", function (event) {
            $("#searchForm").attr("action","${base}/platform/physical/export/").submit();
            dialog.modal("hide");
        });
		
	}
	
	
	function getBatchNo(batchId){
		var a="";
		$.ajax({
			url : "${base!}/platform/physical/getBatchNo",
			data : {batchId : batchId},
			type : "post",
			async : false,
			success : function(data) {
				a=data;
			}
		});
		return a;
		
	}
	
	
</script>
<%}%>
